package com.widen.prima;

import org.eclipse.jface.action.ICoolBarManager;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
import org.eclipse.ui.application.ActionBarAdvisor;
import org.eclipse.ui.application.IActionBarConfigurer;

import com.widen.prima.action.finance.BookOfAccountInputAction;
import com.widen.prima.action.finance.CloseOffAction;
import com.widen.prima.action.finance.InitSystemAction;
import com.widen.prima.action.finance.ManageSubjectAction;
import com.widen.prima.action.finance.ReportBalanceSheetAction;
import com.widen.prima.action.finance.ReportBookOfAccountAction;
import com.widen.prima.action.finance.ReportIncomeStatementAction;
import com.widen.prima.action.finance.ReportSubjectBalanceAction;
import com.widen.prima.action.finance.SubjectBalanceSettingAction;
import com.widen.prima.action.help.OnlineHelpAction;
import com.widen.prima.action.system.BackupAction;
import com.widen.prima.action.system.GetBackAction;
import com.widen.prima.action.system.LockSystemAction;
import com.widen.prima.action.system.SystemSettingAction;

public class ApplicationActionBarAdvisor
    extends ActionBarAdvisor
{
    private IWorkbenchAction exitAction;
    private IWorkbenchAction aboutAction;
    private ManageSubjectAction manageSubjectAction;
    private SubjectBalanceSettingAction initSubjectBalanceAction;
    private BookOfAccountInputAction bookOfAccountInputAction;
    private CloseOffAction closeOffAction;

    private InitSystemAction initSystemAction;
    private SystemSettingAction systemSettingAction;
    private BackupAction backupAction;
    private GetBackAction getBackAction;
    private LockSystemAction lockSystemAction;

    private ReportBookOfAccountAction reportBookOfAccountAction;
    private ReportSubjectBalanceAction reportSubjectBalanceAction;
    private ReportBalanceSheetAction reportBalanceSheetAction;
    private ReportIncomeStatementAction reportIncomeStatementAction;

    private OnlineHelpAction onlineHelpAction;

    public ApplicationActionBarAdvisor(IActionBarConfigurer configurer)
    {
        super(configurer);
    }

    protected void makeActions(IWorkbenchWindow window)
    {
        exitAction = ActionFactory.QUIT.create(window);
        exitAction.setText(Messages
            .getString("ApplicationActionBarAdvisor.exit.action")); //$NON-NLS-1$
        register(exitAction);
        aboutAction = ActionFactory.ABOUT.create(window);
        aboutAction.setText(Messages
            .getString("ApplicationActionBarAdvisor.about.action")); //$NON-NLS-1$
        register(aboutAction);

        systemSettingAction = new SystemSettingAction(window);
        register(systemSettingAction);
        backupAction = new BackupAction(window);
        register(backupAction);
        getBackAction = new GetBackAction(window);
        register(getBackAction);
        lockSystemAction = new LockSystemAction(window);
        register(lockSystemAction);

        initSystemAction = new InitSystemAction(window);
        register(initSystemAction);
        manageSubjectAction = new ManageSubjectAction(window);
        register(manageSubjectAction);
        initSubjectBalanceAction = new SubjectBalanceSettingAction(window);
        register(initSubjectBalanceAction);
        bookOfAccountInputAction = new BookOfAccountInputAction(window);
        register(bookOfAccountInputAction);
        closeOffAction = new CloseOffAction(window);
        register(closeOffAction);
        reportBookOfAccountAction = new ReportBookOfAccountAction(window);
        register(reportBookOfAccountAction);
        reportSubjectBalanceAction = new ReportSubjectBalanceAction(window);
        register(reportSubjectBalanceAction);
        reportBalanceSheetAction = new ReportBalanceSheetAction(window);
        register(reportBalanceSheetAction);
        reportIncomeStatementAction = new ReportIncomeStatementAction(window);
        register(reportIncomeStatementAction);

        onlineHelpAction = new OnlineHelpAction(window);
        register(onlineHelpAction);
    }

    protected void fillMenuBar(IMenuManager menuBar)
    {
        MenuManager fileMenu = new MenuManager(Messages
            .getString("ApplicationActionBarAdvisor.prima"), "prima"); //$NON-NLS-1$ //$NON-NLS-2$

        fileMenu.add(systemSettingAction);
        fileMenu.add(backupAction);
        fileMenu.add(getBackAction);
        fileMenu.add(lockSystemAction);
        fileMenu.add(new Separator());
        fileMenu.add(exitAction);

        MenuManager financeMenu = new MenuManager(Messages
            .getString("ApplicationActionBarAdvisor.finance"), "finance"); //$NON-NLS-1$ //$NON-NLS-2$

        financeMenu.add(initSystemAction);
        financeMenu.add(manageSubjectAction);
        financeMenu.add(initSubjectBalanceAction);
        financeMenu.add(bookOfAccountInputAction);
        financeMenu.add(closeOffAction);
        financeMenu.add(new Separator());
        financeMenu.add(reportBookOfAccountAction);
        financeMenu.add(reportSubjectBalanceAction);
        financeMenu.add(new Separator());
        financeMenu.add(reportBalanceSheetAction);
        financeMenu.add(reportIncomeStatementAction);

        MenuManager windowMenu = new MenuManager(Messages
            .getString("ApplicationActionBarAdvisor.window"), "window"); //$NON-NLS-1$ //$NON-NLS-2$

        MenuManager helpMenu = new MenuManager(Messages
            .getString("ApplicationActionBarAdvisor.help"), "help"); //$NON-NLS-1$ //$NON-NLS-2$

        helpMenu.add(onlineHelpAction);

        helpMenu.add(aboutAction);

        menuBar.add(fileMenu);
        menuBar.add(financeMenu);
        menuBar.add(windowMenu);
        menuBar.add(helpMenu);
    }

    protected void fillCoolBar(ICoolBarManager coolBar)
    {
        IToolBarManager toolbar = new ToolBarManager(coolBar.getStyle());
        coolBar.add(toolbar);

        toolbar.add(systemSettingAction);
        toolbar.add(backupAction);
        toolbar.add(getBackAction);
        toolbar.add(lockSystemAction);
        toolbar.add(new Separator());
        toolbar.add(initSystemAction);
        toolbar.add(manageSubjectAction);
        toolbar.add(initSubjectBalanceAction);
        toolbar.add(bookOfAccountInputAction);
        toolbar.add(closeOffAction);
        toolbar.add(new Separator());
        toolbar.add(reportBookOfAccountAction);
        toolbar.add(reportSubjectBalanceAction);
        toolbar.add(new Separator());
        toolbar.add(reportBalanceSheetAction);
        toolbar.add(reportIncomeStatementAction);
        toolbar.add(new Separator());
        toolbar.add(onlineHelpAction);
    }

    protected void fillTrayItem(IMenuManager trayItem)
    {
        trayItem.add(aboutAction);
        trayItem.add(lockSystemAction);
        trayItem.add(exitAction);
    }

    public LockSystemAction getLockSystemAction()
    {
        return lockSystemAction;
    }
}
